package cn.ycc1.boot3http.controller;

import cn.ycc1.boot3http.util.HttpUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author ycc
 * @date 2024/9/9
 */
@RestController
public class TestController {

    @GetMapping("/test")
    public String test() {
        try {
            // 发送GET请求
//            String getResponse = HttpUtils.get("https://www.baidu.com");
//            System.out.println("GET响应：" + getResponse);

            // 发送POST请求
            String json = "{\"grant_type\":\"sms_code\",\"mobile\":\"13800138001\",\"code\":\"6713\"}"; // 替换为您的JSON数据
            String postResponse = HttpUtils.post("https://example.com/api/gruul-mall-uaa/uaa/auth/oauth/token", json);
            System.out.println("POST响应：" + postResponse);
            JSONObject jsonObject = JSON.parseObject(postResponse);
            System.out.println(jsonObject.get("code"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "test";
    }
}
